//
//  Tools.m
//  YYPHSpeedJump
//
//  Created by sujiang on 15/12/28.
//  Copyright © 2015年 sujiang. All rights reserved.
//

#import "Tools.h"

@interface Tools ()
{
   
}

@end

@implementation Tools

+ (instancetype)shareManager
{
    static Tools *tool = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        tool = [[Tools alloc] init];
        tool.status = YES;
    });
    return tool;
}



+ (void)showAlert:(NSString *)_message //弹出框
{
    UIAlertView *promptAlert = [[UIAlertView alloc] initWithTitle:@"提示" message:_message delegate:nil cancelButtonTitle:@"确定"
                                                otherButtonTitles:nil];
    
    [promptAlert show];
}
+(void)timerFireMethod:(NSTimer *)theTimer //时间
{
    UIAlertView *promptAlert = (UIAlertView *)[theTimer userInfo];
    [promptAlert dismissWithClickedButtonIndex:0 animated:NO];
    promptAlert = NULL;
}


//清除缓存
+ (float)fileSizeAtPath:(NSString *)path
{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    if([fileManager fileExistsAtPath:path]){
        long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize;
        return size/1024.0/1024.0;
    }
    return 0;
}
+ (float)folderSizeAtPath:(NSString *)path
{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    float folderSize;
    if ([fileManager fileExistsAtPath:path]) {
        NSArray *childerFiles=[fileManager subpathsAtPath:path];
        for (NSString *fileName in childerFiles) {
            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
            folderSize +=[self fileSizeAtPath:absolutePath];
        }
    //SDWebImage框架自身计算缓存的实现
        folderSize+=[[SDImageCache sharedImageCache] getSize]/1024.0/1024.0;
        return folderSize;
    }
    return 0;
}

+ (void)clearCache:(NSString *)path
{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        NSArray *childerFiles=[fileManager subpathsAtPath:path];
        for (NSString *fileName in childerFiles) {
            //如有需要，加入条件，过滤掉不想删除的文件
            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
            [fileManager removeItemAtPath:absolutePath error:nil];
        }
    }
    [[SDImageCache sharedImageCache] cleanDisk];
}

+ (NSString *)signDict:(NSDictionary *)dict
{
    // &FCDsw241~%^sjf~93jsfaksjfnc76
    NSMutableString *str = [NSMutableString string];
    NSArray *arr = dict.allKeys;
    NSArray *allkeys = [arr sortedArrayUsingSelector:@selector(compare:)];
    for (NSString *key in allkeys) {
       NSString *tempStr = [NSString stringWithFormat:@"%@=%@", key, dict[key]];
        [str appendFormat:@"&%@", tempStr];
    }
    NSString *string0 = [str stringByAppendingString:@"&FCDsw241~%^sjf~93jsfaksjfnc76"];
    NSString *string1 = [string0 substringFromIndex:1];
   // NSLog(@"________%@", string1);
    NSString *text = [MD5Sign md5:string1];
    NSString *sign = [text substringWithRange:NSMakeRange(3, 26)];
   // NSLog(@"===%@-----------%@", text, sign);
    
    return sign;
}




@end
